<?php
include_once 'MySQLDAO.php';

/**
 * Definition of Class Roomtypes
 * This class represents a data access object for the database table 'roomtypes'.
 */
class Roomtypes {


	public $dao = null;

	private $i = 1;

	/**
	 * associated database field: roomTypeCode, type: varchar, is nullable: false, character set: utf8, max length: 10
	 */
	private $roomTypeCode  = 0;

	/**
	 * associated database field: roomStandardRate, type: float, is nullable: true
	 */
	private $roomStandardRate;

	/**
	 * associated database field: roomTypeDescription, type: varchar, is nullable: true, character set: utf8, max length: 45
	 */
	private $roomTypeDescription;

	/**
	 * associated database field: smokingYN, type: varchar, is nullable: true, character set: utf8, max length: 10
	 */
	private $smokingYN;

	private $rooms = null;

	private $periodroomratesArray = null;



	/**
	 * Default constructor
	 * @param value some value
	 */
	function __construct(){
		$this->dao = new MySQLDao("RoomTypes");
	}


	/**
	 * Initialize the business object with data read from the DB.
	 * @param row database row array containing the values from one read record
	 */
	public function init($row){
		if(isset($row['roomTypeCode'])) $this->roomTypeCode = $row['roomTypeCode'];
		if(isset($row['roomStandardRate'])) $this->roomStandardRate = $row['roomStandardRate'];
		if(isset($row['roomTypeDescription'])) $this->roomTypeDescription = $row['roomTypeDescription'];
		if(isset($row['smokingYN'])) $this->smokingYN = $row['smokingYN'];
	}


	/**
	 * Returns the string representation for this object
	 * @param escapeQuotationMarks boolean value to indicate if quotation marks in value strings should be escaped, default value is true
	 * @return String String representation of Roomtypes
	 */
	public function toString($escapeQuotationMarks=true){
		$s = '[';
		$s .= 'roomTypeCode: '.(($escapeQuotationMarks===true) ? addslashes($this->roomTypeCode) : $this->roomTypeCode).', ';
		$s .= 'roomStandardRate: '.(($escapeQuotationMarks===true) ? addslashes($this->roomStandardRate) : $this->roomStandardRate).', ';
		$s .= 'roomTypeDescription: '.(($escapeQuotationMarks===true) ? addslashes($this->roomTypeDescription) : $this->roomTypeDescription).', ';
		$s .= 'smokingYN: '.(($escapeQuotationMarks===true) ? addslashes($this->smokingYN) : $this->smokingYN);
		$s .= ']';
		return $s;
	}


	/**
	 * Returns the JSON (JavaScript Object Notation) string representation for this object
	 * @return String JSON representation of Roomtypes
	 */
	public function toJSONString(){
		$fieldValues = array ("roomTypeCode"=>$this->roomTypeCode, "roomStandardRate"=>$this->roomStandardRate, "roomTypeDescription"=>$this->roomTypeDescription, "smokingYN"=>$this->smokingYN);
		return json_encode($fieldValues);
	}


	/**
	 * Returns a HTML representation of this object using DIVs for formatting via css
	 * @param escapeHTML boolean value to indicate if value strings should be html escaped, default value is true
	 * @return String the HTML representation of the Roomtypes object
	 */
	public function toHTMLString($escapeHTML=true){
		$htmlCode = "<div class=\"roomtypes\">\n";
		$htmlCode .= '	<div class="roomtypes_roomTypeCode">'.(($escapeHTML===true) ? htmlspecialchars($this->roomTypeCode) : $this->roomTypeCode)."</div>\n";
		$htmlCode .= '	<div class="roomtypes_roomStandardRate">'.(($escapeHTML===true) ? htmlspecialchars($this->roomStandardRate) : $this->roomStandardRate)."</div>\n";
		$htmlCode .= '	<div class="roomtypes_roomTypeDescription">'.(($escapeHTML===true) ? htmlspecialchars($this->roomTypeDescription) : $this->roomTypeDescription)."</div>\n";
		$htmlCode .= '	<div class="roomtypes_smokingYN">'.(($escapeHTML===true) ? htmlspecialchars($this->smokingYN) : $this->smokingYN)."</div>\n";
		$htmlCode .= "</div>\n";
		return $htmlCode;
	}
	/*
	public function getData($where) {
		$rows = $this->dao->getData($where);
		return $rows;
	}*/



	public static function loadAll(){
		$roomtypes = new Roomtypes();
		$rows = $roomtypes->dao->getData("");
		$roomtypess = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Roomtypes();
			$d->init($rows[$index]);
			array_push($roomtypess,$d);
		}
		return $roomtypess;
	}


	/**
	 * Load the Roomtypes uniquely by its primary key.
	 * @param roomTypeCode the primary key
	 * @return Roomtypes Instance of {@link Roomtypes}
	 */
	public static function loadUnique($roomTypeCode){
		$roomtypes = new Roomtypes();
		$rows = $roomtypes->dao->getData("`roomTypeCode`='$roomTypeCode'");
		$roomtypes->init($rows[0]);
		return $roomtypes;
	}


	/**
	 * Insert this object into the DB
	 * @return number new id (auto increment value) genereated
	 */
	public function insert(){
		$list = array("roomTypeCode"=>$this->roomTypeCode, "roomStandardRate"=>$this->roomStandardRate, "roomTypeDescription"=>$this->roomTypeDescription, "smokingYN"=>$this->smokingYN);
		return $this->dao->insertRecord($list);
	}


	/**
	 * Update this object into the DB
	 * @return number the number of updated records
	 */
	public function update(){
		$list = array("roomTypeCode"=>$this->roomTypeCode, "roomStandardRate"=>$this->roomStandardRate, "roomTypeDescription"=>$this->roomTypeDescription, "smokingYN"=>$this->smokingYN);
		$where = "`roomTypeCode`='$roomTypeCode'";
		return $this->dao->updateRecord($list,$where);
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initPOST(){
		if (isset($_POST['roomTypeCode'])){
			$this->roomTypeCode = $_POST['roomTypeCode'];
		}
		if (isset($_POST['roomStandardRate'])){
			$this->roomStandardRate = $_POST['roomStandardRate'];
		}
		if (isset($_POST['roomTypeDescription'])){
			$this->roomTypeDescription = $_POST['roomTypeDescription'];
		}
		if (isset($_POST['smokingYN'])){
			$this->smokingYN = $_POST['smokingYN'];
		}
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initGET(){
		if (isset($_GET['roomTypeCode'])){
			$this->roomTypeCode = $_GET['roomTypeCode'];
		}
		if (isset($_GET['roomStandardRate'])){
			$this->roomStandardRate = $_GET['roomStandardRate'];
		}
		if (isset($_GET['roomTypeDescription'])){
			$this->roomTypeDescription = $_GET['roomTypeDescription'];
		}
		if (isset($_GET['smokingYN'])){
			$this->smokingYN = $_GET['smokingYN'];
		}
	}


	/**
	 * Returns the value from the database field roomTypeCode.
	 * In the database the field roomTypeCode is of type varchar.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getRoomTypeCode(){
		return $this->roomTypeCode;
	}


	/**
	 * Set the value from the database field roomTypeCode.
	 * In the database the field roomTypeCode is of type varchar.
	 * The database field is NOT nullable.
	 * @param roomTypeCode String with the value for the field to be set
	 */
	public function setRoomTypeCode($roomTypeCode){
		if(strlen($roomTypeCode) > 10) throw new Exception("roomTypeCode does not allow strings longer than 10 characters. The submitted string contains ".strlen($roomTypeCode)." characters.");
		$this->roomTypeCode = $roomTypeCode;
	}


	/**
	 * Returns the value from the database field roomStandardRate.
	 * In the database the field roomStandardRate is of type float.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getRoomStandardRate(){
		return $this->roomStandardRate;
	}


	/**
	 * Set the value from the database field roomStandardRate.
	 * In the database the field roomStandardRate is of type float.
	 * The database field is  nullable.
	 * @param roomStandardRate String with the value for the field to be set
	 */
	public function setRoomStandardRate($roomStandardRate){
		$this->roomStandardRate = $roomStandardRate;
	}


	/**
	 * Returns the value from the database field roomTypeDescription.
	 * In the database the field roomTypeDescription is of type varchar.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getRoomTypeDescription(){
		return $this->roomTypeDescription;
	}


	/**
	 * Set the value from the database field roomTypeDescription.
	 * In the database the field roomTypeDescription is of type varchar.
	 * The database field is  nullable.
	 * @param roomTypeDescription String with the value for the field to be set
	 */
	public function setRoomTypeDescription($roomTypeDescription){
		if(strlen($roomTypeDescription) > 45) throw new Exception("roomTypeDescription does not allow strings longer than 45 characters. The submitted string contains ".strlen($roomTypeDescription)." characters.");
		$this->roomTypeDescription = $roomTypeDescription;
	}


	/**
	 * Returns the value from the database field smokingYN.
	 * In the database the field smokingYN is of type varchar.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getSmokingYN(){
		return $this->smokingYN;
	}


	/**
	 * Set the value from the database field smokingYN.
	 * In the database the field smokingYN is of type varchar.
	 * The database field is  nullable.
	 * @param smokingYN String with the value for the field to be set
	 */
	public function setSmokingYN($smokingYN){
		if(strlen($smokingYN) > 10) throw new Exception("smokingYN does not allow strings longer than 10 characters. The submitted string contains ".strlen($smokingYN)." characters.");
		$this->smokingYN = $smokingYN;
	}


	/**
	 * Returns an object array containing all linked Periodroomrates objects.
	 * A One to Many(1:n) relation exists between the Roomtypes and the Periodroomrates.
	 * @return Periodroomrates[] Array of Periodroomrates instances
	 */
	public function getPeriodroomratess(){
	if($this->periodroomratesArray == null){
			$this->periodroomratesArray = array();
			$tempperiodroomrates = new Periodroomrates();
			$dataRowsTemp = $tempperiodroomrates->dao->getData("`roomTypeCode` = '$this->roomTypeCode'");
			if(count($dataRowsTemp)  > 0)
			foreach($dataRowsTemp as $dataRow){
				$tempPeriodroomrates = new Periodroomrates();
				$tempPeriodroomrates->init($dataRow);
				array_push($this->periodroomratesArray , $tempPeriodroomrates);
			}
		}
		return $this->periodroomratesArray;
	}


	/**
	 * Set a link to a related Rooms instance
	 * @param targetObjectInstanceName instance of Rooms to be linked to this object instance
	 */
	public function setRooms($rooms){
		$rooms->roomTypeCode = $this->roomTypeCode;
		$this->rooms = $rooms;
	}


	/**
	 * Set links to related Periodroomrates instances. Existing links will be overwritten
	 * @param periodroomratesArray array of Periodroomrates instances to be linked to this object instance
	 */
	public function setPeriodroomratess($periodroomratesArray){
		foreach($periodroomratesArray as $periodroomrates)
			$periodroomrates->roomTypeCode = $this->roomTypeCode;
		$this->periodroomratesArray = $periodroomratesArray;
	}


	/**
	 * Add a link to object of type Periodroomrates
	 * @param periodroomrates instance of Periodroomrates to be linked to this object instance
	 */
	public function addPeriodroomrates($periodroomrates){
		$periodroomrates->roomTypeCode = $this->roomTypeCode;
		if($this->periodroomratesArray == null) $this->periodroomratesArray = array();
		array_push($this->periodroomratesArray, $periodroomrates);
	}
}
?>